<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>线下还款申请记录表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <%--    <div class="searchArea">--%>
    <%--        <form id="searchBar">--%>
    <%--            <div class="fieldset1 clearFix">--%>
    <%--                <div class="fieldBox">--%>
    <%--                    <div class="label">合同号</div>--%>
    <%--                    <div class="field">--%>
    <%--                        <input name="searchCrCntNo" id="searchCrCntNo" type="text" class="ui-textbox" value="">--%>
    <%--                        <span class="requiredSymbol">*</span>--%>
    <%--                    </div>--%>
    <%--                </div>--%>
    <%--                <div class="fieldBox">--%>
    <%--                    <div class="label">实还时间</div>--%>
    <%--                    <div class="field">--%>
    <%--                        <input name="searchActPayDt" id="searchActPayDt" type="text" class="ui-datepicker" value="">--%>
    <%--                        <span class="requiredSymbol">*</span>--%>
    <%--                    </div>--%>
    <%--                </div>--%>
    <%--                <div class="clearFix"></div>--%>

    <%--            </div>--%>
    <%--        </form>--%>
    <%--    </div>--%>
    <div class="insOfflineRepayLogForm">
        <form id="insOfflineRepayLogForm">
            <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                <div class="sqPanel normal">
                    <div class="sqPanel_head TL">
                        <span>查询条件</span>
                    </div>
                    <div class="sqPanel_body">
                        <div class="fieldBox col_50">
                            <div class="label">合同号</div>
                            <div class="field">
                                <input name="crCntNo" id="crCntNo" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox col_50">
                            <div class="label">线下还款时间</div>
                            <div class="field">
                                <input name="actPayDt" id="actPayDt" type="text" class="ui-datepicker"
                                       class="ui-textbox"
                                       value="">
                            </div>
                        </div>
                        <div class="fieldBox col_50">
                            <div class="label">还款类型</div>
                            <div class="field">
                                <select name="repayTypCd" id="repayTypCd" class="data-comboboxid" data-value=""
                                        validate="{required:true,select:true}">
                                    <option value=" " seleted>--请选择--</option>
                                    <c:forEach items="${repayTypCdList }" var="kv">
                                        <option value="${kv.key }">${kv.value }</option>
                                    </c:forEach>
                                </select>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_50">
                            <div class="label">应还金额</div>
                            <div class="field">
                                <input name="repayAmt" id="repayAmt" type="text" class="ui-textbox" value=""
                                       readonly="readonly">
                            </div>
                        </div>
                    </div>
                </div>
<%--                <div class="sqPanel normal">--%>
<%--                    <div class="sqPanel_head TL">--%>
<%--                        <span>还款计划</span>--%>
<%--                    </div>--%>
<%--                    <div class="sqPanel_body">--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">还款类型</div>--%>
<%--                            <div class="field">--%>
<%--                                <select name="repayTypCd" id="repayTypCd" class="data-comboboxid" data-value=""--%>
<%--                                        validate="{required:true,select:true}">--%>
<%--                                    <option value=" " seleted>--请选择--</option>--%>
<%--                                    <c:forEach items="${repayTypCdList }" var="kv">--%>
<%--                                        <option value="${kv.key }">${kv.value }</option>--%>
<%--                                    </c:forEach>--%>
<%--                                </select>--%>
<%--                                <span class="requiredSymbol">*</span>--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">按期应还金额</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="repayAmt" id="repayAmt" type="text" class="ui-textbox" value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">结清应还金额</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="settlePayAmt" id="settlePayAmt" type="text" class="ui-textbox" value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">结清应还本金</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="repayAmt" id="settlePayPrincipal" type="text" class="ui-textbox" value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">结清应还利息</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="settlePayInterest" id="settlePayInterest" type="text" class="ui-textbox" value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">结清应还罚息</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="settlePayOverdueInterest" id="settlePayOverdueInterest" type="text" class="ui-textbox"--%>
<%--                                       value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">结清应还正常担保费</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="settlePayFee" id="settlePayFee" type="text" class="ui-textbox" value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                        <div class="fieldBox col_50">--%>
<%--                            <div class="label">结清应还逾期担保费</div>--%>
<%--                            <div class="field">--%>
<%--                                <input name="settlePayOverdueFee" id="settlePayOverdueFee" type="text" class="ui-textbox" value=""--%>
<%--                                       readonly="readonly">--%>
<%--                            </div>--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                </div>--%>
            </div>

            <div class="btnsBox">
                <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>还款试算</span>
            </div>
        </form>
    </div>
    <div id="ligergrid" class="sq-grid"></div>

    <div id="btnsBox" class="btnsBox" style="text-align: center;">
        <span id="saveCapPayInfoBtn" class="sq-button sq-button-round">保存</span>
    </div>
</div>
<script>
	var grid = null, menu = null;
	$(function () {
	    var _applyLogId = "${insOfflineRepayLogVO.id}";//主键ID

		grid = $("#ligergrid").ligerGrid({
<%--			url: '<%=path%>/repay/insOfflineRepayLog/queryReplayPlan.do',--%>
<%--			param: {applyLogId:_applyLogId},--%>
			method: 'get',
			columns: [
				{display: '期次', name: 'payPd', minWidth: 100, align: 'left', enabledSort: false},
<%--				{display: '还款状态', name: 'repayState', minWidth: 100, align: 'left', hide: true},--%>
				{display: '本金', name: 'capAmt', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.capAmt/100);
					}
				},
				{display: '利息', name: 'intrAmt', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.intrAmt/100);
					}
				},
				{display: '罚息', name: 'pntAmt', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.pntAmt/100);
					}
				},
				{display: '担保费', name: 'grtAmt', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.grtAmt/100);
					}
				},
				{display: '逾期担保费', name: 'ovdGrtAmt', minWidth: 100, align: 'left', enabledSort: false,
				    render:function(rowdata,index,value){
						return '&yen;'+FormatMoney(rowdata.ovdGrtAmt/100);
					}
				},
                {display: '违约金', name: 'damAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.damAmt/100);
                    }
                },
			],
			usePager: false,
			root: 'rows',
			record: 'total',
			hideLoadButton: true,
			width: '100%',
			height: 400,
			heightDiff: -2,
			checkbox: true,
			rownumbers: true,
			allowUnSelectRow: true,
			alternatingRow: false,
			onSelectRow: function(rowData, rowid, rowobj){
                calcRepayAmt();
			},
			onUnSelectRow : function(rowData, rowid, rowobj){
			    calcRepayAmt();
			},
		});
		grid.setHeight(100);

		function calcRepayAmt(){
		    var _repayAmt = 0;
            var selectedRows = grid.getSelectedRows();
            for (var index in selectedRows) {
                _repayAmt = _repayAmt + selectedRows[index].capAmt + selectedRows[index].intrAmt
                    + selectedRows[index].pntAmt  + selectedRows[index].grtAmt
                    + selectedRows[index].ovdGrtAmt + selectedRows[index].damAmt
            }
            $("#repayAmt").val(_repayAmt/100);
		}

<%--		$("#searchBar").ligerForm();--%>
		$("#insOfflineRepayLogForm").ligerForm();
		$("#pageloading").hide();

		/* 查询 */
		$("#searchBtn").click(function (event) {
<%--			var form = liger.get("searchBar");--%>
<%--			var data = form.getData();--%>
<%--			for (name in data) {--%>
<%--				grid.setParm(name, data[name]);--%>
<%--			}--%>
			var form = liger.get("insOfflineRepayLogForm");
			var formData = form.getData();

			var _crCntNo = formData["crCntNo"];
			var _actPayDt = formData["actPayDt"];
			var _repayTypCd = formData["repayTypCd"];
			if( _crCntNo == ''){
				$.ligerDialog.SQalert({content:'请输入合同号', SQ_type: "warring"});
				return;
			}
            if( _actPayDt == ''){
				$.ligerDialog.SQalert({content:'请输入线下还款日期', SQ_type: "warring"});
				return;
			}
			if( _repayTypCd == ' '){
				$.ligerDialog.SQalert({content:'请选择还款类型', SQ_type: "warring"});
				return;
			}

			grid.setParm("crCntNo", formData["crCntNo"]);
            grid.setParm("actPayDt", formData["actPayDt"]);
            grid.setParm("repayTypCd", formData["repayTypCd"]);
            grid._setUrl("<%=path%>/repay/insOfflineRepayLog/queryReplayPlan.do");
			grid.reload();
		});


		$("#saveCapPayInfoBtn").click(function (event) {
			//$(document).trigger('click');
			var _repayTypCd = $("#repayTypCd").val();
			if( _repayTypCd == ' '){
				$.ligerDialog.SQalert({content:'请选择还款类型', SQ_type: "warring"});
				return;
			}

			var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }

			var form = liger.get("insOfflineRepayLogForm");
			var formData = form.getData();

            var repayPlans = [];
            for (var index in selectedRows) {
                repayPlans.push(selectedRows[index]);
            }
			formData["repayPlans"] = JSON.stringify(repayPlans);

            $.ligerDialog.confirm(LogUtils.LOG_CMM_SUBMIT_CONFIRM_CONTENT_001, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: formData,
                    url: '<%=path%>/repay/insOfflineRepayLog/add.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                            $("#saveCapPayInfoBtn").attr("style","text-align:center;display: none;");
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
		});
	});

	//格式化时间
	function renderDate(rowdata, index, value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
</script>
</body>
</html>
